#include "myLib.h"
#include "commandLib.h"
#include "images.h"
#include <stdlib.h>


int main()
{
	REG_DISPCTL = MODE4 | BG2_ENABLE;
	//FlipPage();
	for(int i = 0; i< IMAGES_PALETTE_SIZE;i++)
		PALETTE[i] = images_palette[i];
	newGame();
	int aPressed = 0;
	int selPressed = 0;
	int aPressedNow = 0;
	int selPressedNow = 0;
	while(1)
	{
		checkWinConditions();
		checkLoseConditions();
		/*Button Listeners*/
		if(KEY_DOWN_NOW(BUTTON_LEFT))
			cursorLeft();
		if(KEY_DOWN_NOW(BUTTON_RIGHT))
			cursorRight();
		if(KEY_DOWN_NOW(BUTTON_DOWN))
			cursorDown();
		if(KEY_DOWN_NOW(BUTTON_UP))
			cursorUp();
		aPressedNow = KEY_DOWN_NOW(BUTTON_A);
		selPressedNow = KEY_DOWN_NOW(BUTTON_SELECT);
		if(aPressedNow && (!aPressed))
			fireCounterMissile();
		if(selPressedNow && (!selPressed))
			newGame();
		aPressed = aPressedNow;
		selPressed = selPressedNow;
		/*Updating positions*/
		attemptEnemyMissile();
		updateMissiles();
		//updateCounterMissiles();
		checkCollisions();
		/*Last Things to happen*/
		drawScreen();
		waitForVblank();
		FlipPage();
	}
}
